package com.molichuxing.gateway.utils;

import com.molichuxing.framework.utils.EmailUtil;
import com.molichuxing.gateway.property.EmailTemplateEnum;
import com.molichuxing.gateway.property.SystemNameEnum;
import com.molichuxing.services.business.service.AccountBizService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

/**
 * 用户token工具类
 *
 * @author zoumingyu
 * @date 2019年8月19日
 *
 */
@Component
public class OpEmailUtil {
	private static final Logger logger = LoggerFactory.getLogger(OpEmailUtil.class);

	// 开关
	@Value("${email.enable}")
	private String enable;

	@Value("${op.system.url}")
	private String opSystemUrl;

	@Value("${iov.system.url}")
	private String iovSystemUrl;

	@Value("${dealer.system.url}")
	private String dealerSystemUrl;

	@Value("${email_account}")
	private String emailAccount;

	@Value("${email_password}")
	private String emailPassword;

	/**
	 * 发送邮件
	 * @param subject 标题
	 * @param content 内容
	 * @param emailTo 收件人
	 * @return
	 */
	public boolean send(String subject, String content, String emailTo) {
		return EmailUtil.sendMail(emailAccount, emailPassword, subject, content, emailTo);
	}

	/**
	 * 创建op账号成功
	 * @param account
	 * @param password
	 * @return
	 */
	public String editorCreateOpAccountSuccessContent(String account, String password) {
		String content = EmailTemplateEnum.CREATE_OP_ACCOUNT_SUCCESS.getTemplate();
		content = content.replace("${systemName}", SystemNameEnum.OP_AND_IOV.getName());
		content = content.replace("${opSystemName}", SystemNameEnum.OP.getName());
		content = content.replace("${opSystemUrl}", opSystemUrl);
		content = content.replace("${iovSystemName}", SystemNameEnum.IOV.getName());
		content = content.replace("${iovSystemUrl}", iovSystemUrl);
		content = content.replace("${userName}", account);
		content = content.replace("${password}", password);
		return content;
	}

	/**
	 * 创建经销商用户成功
	 * @param account
	 * @param password
	 * @return
	 */
	public String editorCreateDealerAccountSuccessContent(String account, String password) {
		String content = EmailTemplateEnum.CREATE_DEALER_ACCOUNT_SUCCESS.getTemplate();
		content = content.replace("${systemName}", SystemNameEnum.DEALER.getName());
		content = content.replace("${systemUrl}", dealerSystemUrl);
		content = content.replace("${userName}", account);
		content = content.replace("${password}", password);
		return content;
	}

	/**
	 * 创建用户失败
	 * @param realName
	 * @return
	 */
	public String editorCreateAccountErrorContent(SystemNameEnum systemName, String realName) {
		String content = EmailTemplateEnum.CREATE_ACCOUNT_ERROR.getTemplate();
		content = content.replace("${systemName}", systemName.getName());
		content = content.replace("${realName}", realName);
		return content;
	}

	public String
	editorResetPasswordContent(SystemNameEnum systemName, String account, String password) {
		String content = EmailTemplateEnum.RESET_PASSWORD.getTemplate();
		content = content.replace("${systemName}", systemName.getName());
		content = content.replace("${userName}", account);
		content = content.replace("${password}", password);
		return content;
	}
}
